<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

function format_time($time) {
    $time_difference = time() - strtotime($time);
    $format_list = array(
        '31536000'=>'年',
        '2592000'=>'个月',
        '604800'=>'周',
        '86400'=>'天',
        '3600'=>'小时',
        '60'=>'分钟',
        '1'=>'秒'
    );

    foreach ($format_list as $key => $value)    {
        $result = floor($time_difference/(int)$key);

        if ($result != 0) {
            return $result.$value.'前';
        }
    }
    return '1秒前';
}